package com.bianguo.android.baidumapdemo.activity;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.bianguo.android.baidumapdemo.BaseActivity;
import com.bianguo.android.baidumapdemo.R;
import com.bianguo.android.baidumapdemo.adapter.GoodsAdapter;
import com.bianguo.android.baidumapdemo.adapter.InfoAdapter;
import com.bianguo.android.baidumapdemo.entity.GoodsData;
import com.bianguo.android.baidumapdemo.widget.ItemHeaderDecoration;
import com.bianguo.android.baidumapdemo.widget.PaletteView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class PaletteActivity extends BaseActivity {

    @BindView(R.id.menu_list)
    RecyclerView menuRv;
    @BindView(R.id.goods_list)
    RecyclerView goodsRv;

    private ArrayList<String> menus;
    private InfoAdapter menuAdapter;
    private GridLayoutManager goodsLayoutManager;
    private ArrayList<GoodsData> goodsDatas;
    private GoodsAdapter goodsAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_palette;
    }

    @Override
    protected void initView(@Nullable Bundle saveInstanceState) {
        menus = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            menus.add("菜单 --> " + i);
        }
        menuAdapter = new InfoAdapter(mContext, menus);
        menuRv.setAdapter(menuAdapter);

        goodsDatas = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            GoodsData data = new GoodsData();
            data.setTitle(true);
            data.setTag(i + "");
            data.setGoodsName("菜单 --> " + i);
            goodsDatas.add(data);
            for (int j = 0; j < 15; j++) {
                GoodsData goodsData = new GoodsData();
                goodsData.setTitle(false);
                goodsData.setTag(i + "");
                goodsData.setGoodsName("商品 " + j);
                goodsDatas.add(goodsData);
            }
        }
        goodsLayoutManager = new GridLayoutManager(mContext, 3);
        goodsLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return goodsDatas.get(position).isTitle() ? 3 : 1;
            }
        });
        goodsRv.setLayoutManager(goodsLayoutManager);
        goodsRv.addItemDecoration(new ItemHeaderDecoration(mContext, goodsDatas));
        goodsAdapter = new GoodsAdapter(mContext, goodsDatas);
        goodsRv.setAdapter(goodsAdapter);
    }
}
